package com.monster.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * description:
 *
 * @author Yuanml on 2021/1/9 16:07
 */
public class MyInterceptor2 implements HandlerInterceptor {
    /**
     * description:
     * 预处理，在controller方法执行之前执行
     * @param request     http请求对象
     * @param response      http响应对象
     * @param handler       被拦截的控制器对象
     * @return
     * @author Yuanml
     * @date 2021/1/9 4:12 下午
     **/
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("---------2-------->preHandle");
//        request.getRequestDispatcher("/tips.jsp").forward(request, response);
        return true;
    }

    /**
     * description:
     * 后处理方法，在controller方法处理之后执行
     * @param request
     * @param response
     * @param handler           被 拦截的controller对象
     * @param modelAndView      controller返回值
     * @return
     * @author Yuanml
     * @date 2021/1/9 4:15 下午
     **/
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("---------2-------->postHandle");
    }

    /**
     * description:
     * 最后执行的方法，一般当视图处理完，进行了forward之后，就视为处理 完成了
     * @param request
     * @param response
     * @param handler           被 拦截的controller对象
     * @param ex                程序中发生的异常
     * @return
     * @author Yuanml
     * @date 2021/1/9 4:17 下午
     **/
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("----------2------->afterCompletion");
    }
}
